unit Utils;

interface
function EnsureBackSlash(Dir:string):string;
function EnsureNoBackSlash(Dir:string):string;
function ParentDir(Dir:string):string;

implementation
function EnsureBackSlash(Dir:string):string;
begin
  Result := Dir ;
  if Result[Length(Result)] <>'\' then
    Result := Result + '\';
end;
function EnsureNoBackSlash(Dir:string):string;
begin
  Result := Dir ;
  if Result[Length(Result)] ='\' then
    SetLength( Result,Length(result)-1);
end;
function ParentDir(Dir:string):string;
var t : String ; i : Integer ;
begin
  if Length(EnsureBackSlash(dir))=3 then
    result := Dir
  else begin
    t := EnsureNoBackSlash(Dir) ;
    i := Length(t);
    while(i>0) and (t[i] <> '\') do begin
      SetLength(t,i-1);
      Dec(i);
    end;
    result := t ;
  end;
end;
end.
 